package net.suncaper.psychological.service.impl;

import net.suncaper.psychological.mapper.VisitRecordMapper;
import net.suncaper.psychological.mapper.impl.VisitRecordMapperImpl;
import net.suncaper.psychological.model.domain.VisitRecord;
import net.suncaper.psychological.service.IVisitRecordService;
import java.util.List;
import java.util.Map;

public class VisitRecordServiceImpl implements IVisitRecordService {
    private final VisitRecordMapper visitRecordMapper = new VisitRecordMapperImpl();

    @Override
    public boolean addVisitRecord(VisitRecord visitRecord) {
        return visitRecordMapper.insertVisitRecord(visitRecord) > 0;
    }

    @Override
    public List<VisitRecord> getInitialVisitRecords() {
        return visitRecordMapper.selectInitialVisitRecords();
    }

    @Override
    public VisitRecord getVisitRecordById(Long id) {
        return visitRecordMapper.selectVisitRecordById(id);
    }

    @Override
    public List<VisitRecord> getVisitRecordsByAppointmentId(Long appointmentId) {
        return visitRecordMapper.selectVisitRecordsByAppointmentId(appointmentId);
    }

    @Override
    public boolean updateVisitRecordType(Long id, String type) {
        return visitRecordMapper.updateVisitRecordType(id, type) > 0;
    }

    @Override
    public boolean rejectVisitRecord(Long id, Long appointmentId) {
        boolean deleted = visitRecordMapper.deleteVisitRecordById(id) > 0;
        if (appointmentId != null) {
            net.suncaper.psychological.service.IAppointmentService appointmentService = new net.suncaper.psychological.service.impl.AppointmentServiceImpl();
            appointmentService.updateAppointmentStatus(appointmentId, "APPROVED");
        }
        return deleted;
    }

    @Override
    public List<VisitRecord> getConsultVisitRecords() {
        return visitRecordMapper.selectConsultVisitRecords();
    }

    @Override
    public List<Map<String, Object>> getConsultVisitRecordsWithAppointment() {
        return visitRecordMapper.selectConsultVisitRecordsWithAppointment();
    }
} 